window.onload=function(){
  var ticket = document.getElementById('pleat_number');
  var selticket = document.getElementById('selticket');
  var ticket_ul = selticket.getElementsByTagName('ul');
  var ticket_li = selticket.getElementsByTagName('li');
  var btn_perv = document.getElementById('perv');
  var btn_next = document.getElementById('next');
  btn_next.onclick = function(){
    for(var j=0;j<ticket_ul.length;j++){
      if(ticket_ul[j].style.display == "block"){
        ticket_ul[j].style.display = "none";
        ticket_ul[j+1].style.display = "block";
        break;
      }
      if(ticket_ul[ticket_ul.length-1].style.display == "block"){
        ticket_ul[ticket_ul.length-1].style.display = "none";
        ticket_ul[0].style.display = "block";
      }
    }
  }
  btn_perv.onclick = function(){
      for(var j=ticket_ul.length-1;j>0;j--){
        if(ticket_ul[j].style.display == "block"){
          ticket_ul[j].style.display = "none";
          ticket_ul[j-1].style.display = "block";
          break;
        }
        if(ticket_ul[0].style.display == "block"){
          ticket_ul[0].style.display = "none";
          ticket_ul[ticket_ul.length-1].style.display = "block";
        }
      }
  }
  for (var i = 0; i < ticket_li.length; i++) {
    ticket_li[i].onclick = function(){
      ticket.value = this.innerHTML;
      selticket.style.display = "none";
    }
  }
  ticket.onclick = function(){
    selticket.style.display = "block";
  }
}